package servlet.annotationServlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
    name = "annotationServlet",
    urlPatterns = {"/annotation", "/an"},
    loadOnStartup = 3,
    initParams = {
        @WebInitParam(name = "userName", value = "xxxx"),
        @WebInitParam(name = "passWord", value = "yyyyy")
    })
public class AnnotationServlet extends HttpServlet {

  @Override
  public void init() throws ServletException {
    System.out.println("load on startup before user visit");
    System.out.println(getInitParameter("userName"));
    System.out.println(getInitParameter("passWord"));
  }

  @Override
  protected void doPost(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {
    response.getWriter().write("hello world from annotation servlet");
  }

  @Override
  protected void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {
    doPost(request, response);
  }
}
